﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BuySoftwareOnline.Domain.Abstract;

namespace BuySoftwareOnline.Domain.Concrete
{
    public class SupplierRepository : ISupplierRepository
    {
        BuySoftwareOnlineDataContext context;

        public SupplierRepository()
        {
            context = new BuySoftwareOnlineDataContext();
        }

        public IQueryable<Supplier> Suppliers
        {
            get { return context.Suppliers; }
        }

        public void SaveSupplier(Supplier supplier)
        {
            if (supplier.SupplierID == 0)
            {
                context.Suppliers.InsertOnSubmit(supplier);
            }
            else
            {
                context.Suppliers.Attach(supplier);
                context.Refresh(System.Data.Linq.RefreshMode.KeepCurrentValues, supplier);
            }
            context.SubmitChanges();
        }

        public void DeleteSupplier(Supplier supplier)
        {
            context.Suppliers.DeleteOnSubmit(supplier);
            context.SubmitChanges();
        }
    }
}
